﻿package mortal.game.view.copy.wine.view
{
    import Message.Game.*;
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.copy.wine.data.*;
    import mortal.game.view.copy.wine.renderer.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class WinePartyDonateRankWin extends BaseWindow
    {
        private var _rankList:GTileList;
        private var _pageSelecter:PageSelecter;
        private var _myRankLink:GTextFiled;
        private var _myRank:GTextFiled;
        private static var _instance:WinePartyDonateRankWin;

        public function WinePartyDonateRankWin(param1:ILayer = null)
        {
            super(param1);
            if (_instance)
            {
                throw new Error("WineDonateRankWin 单例");
            }
            setSize(317, 426 - 6);
            title = Language.getString(40998);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(7, 35, 306, 359, this));
            this.pushUIToDisposeVec(UIFactory.bg(7, (35 + 1), 306, 23, this, ImagesConst.RegionTitleBg));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40999), 24, 40 - 3, 40, 20, this, GlobalStyle.textFormatBai));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41000), 102, 40 - 3, 40, 20, this, GlobalStyle.textFormatBai));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41001), 190, 40 - 3, 40, 20, this, GlobalStyle.textFormatBai));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41002), 260 - 4, 40 - 3, 40, 20, this, GlobalStyle.textFormatBai));
            this._rankList = UIFactory.tileList(7, 36 + 24, 306, 281, this);
            this._rankList.columnWidth = 306;
            this._rankList.rowHeight = 28;
            this._rankList.horizontalGap = 0;
            this._rankList.verticalGap = 0;
            this._rankList.setStyle("skin", new Bitmap());
            this._rankList.setStyle("cellRenderer", WineDonateRankCellRenderer);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._pageSelecter = UIFactory.pageSelecter(7 + 82, 35 + 330, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.InputDisablBg, _loc_1);
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            var _loc_2:* = GlobalStyle.textFormatLv;
            _loc_2.size = 14;
            this._myRankLink = UIFactory.gTextField("", 7 + 102, 35 + 362, 76, 25, this, _loc_2);
            this._myRankLink.htmlText = HTMLUtil.addLink(Language.getString(41003), GlobalStyle.colorLv) + "：";
            this._myRankLink.configEventListener(TextEvent.LINK, this.onLinkHandler);
            this._myRankLink.configEventListener(MouseEvent.MOUSE_OVER, this.onOverHandler);
            this._myRankLink.configEventListener(MouseEvent.MOUSE_OUT, this.onOutHandler);
            this._myRank = UIFactory.gTextField("", 7 + 173, 35 + 363, 45, 25, this, _loc_2);
            this.addListeners();
            this.reqRankList();
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.WinePartyGetDonateList, this.onGetDonateListHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.WinePartyGetDonateList, this.onGetDonateListHandler);
            return;
        }// end function

        private function reqRankList() : void
        {
            GameProxy.guild.getWinePartyDonateList();
            return;
        }// end function

        private function initRankList() : void
        {
            var _loc_4:WineDonateRankData = null;
            var _loc_1:Array = [];
            var _loc_2:int = 1;
            while (_loc_2 <= 10)
            {
                
                _loc_4 = new WineDonateRankData();
                _loc_4.rank = _loc_2;
                _loc_4.roleName = "玩家名字七个字";
                _loc_4.rolePosition = "会长";
                _loc_4.fundsNum = 99999;
                _loc_1.push(_loc_4);
                _loc_2++;
            }
            var _loc_3:* = new DataProvider();
            _loc_3.addItems(_loc_1);
            this._rankList.dataProvider = _loc_3;
            this._rankList.drawNow();
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateList();
            return;
        }// end function

        private function onLinkHandler(event:TextEvent) : void
        {
            return;
        }// end function

        private function onOverHandler(event:MouseEvent) : void
        {
            CursorManager.showCursor(CursorManager.BUTTON);
            return;
        }// end function

        private function onOutHandler(event:MouseEvent) : void
        {
            CursorManager.hideFromButton();
            return;
        }// end function

        private function onGetDonateListHandler(param1:Object) : void
        {
            var _loc_2:* = param1 as Array;
            Cache.instance.copy.wineParty.winePartyDonateArr = _loc_2;
            this.updatePageInfo();
            this.updateList();
            return;
        }// end function

        private function updateList() : void
        {
            var _loc_7:SGuildWinePartyRank = null;
            var _loc_8:DataProvider = null;
            var _loc_9:WineDonateRankData = null;
            var _loc_1:* = Cache.instance.copy.wineParty.winePartyDonateArr;
            var _loc_2:* = this._pageSelecter.currentPage;
            var _loc_3:* = (this._pageSelecter.currentPage - 1) * 10;
            var _loc_4:* = this._pageSelecter.currentPage * 10;
            var _loc_5:* = _loc_1.slice(_loc_3, _loc_4);
            var _loc_6:Array = [];
            for each (_loc_7 in _loc_5)
            {
                
                _loc_9 = new WineDonateRankData();
                _loc_9.rank = _loc_7.rank;
                _loc_9.roleName = _loc_7.name;
                _loc_9.rolePosition = GameDefConfig.instance.getItem("EGuildPostion", _loc_7.position).text;
                _loc_9.fundsNum = _loc_7.money;
                _loc_6.push(_loc_9);
                if (_loc_7.name == Cache.instance.role.entityInfo.name)
                {
                    this._myRank.text = _loc_7.rank + "";
                }
            }
            _loc_8 = new DataProvider();
            _loc_8.addItems(_loc_6);
            this._rankList.dataProvider = _loc_8;
            this._rankList.drawNow();
            return;
        }// end function

        private function updatePageInfo() : void
        {
            var _loc_1:* = Cache.instance.copy.wineParty.winePartyDonateArr;
            this._pageSelecter.maxPage = int(Math.ceil(_loc_1.length / 10));
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show();
            if (!DonateFundsTipWin.instance.isHide)
            {
                this.x = DonateFundsTipWin.instance.x + DonateFundsTipWin.instance.width + 10;
            }
            else
            {
                this.x = (Global.stage.stageWidth - this.width) / 2;
                this.y = (Global.stage.stageHeight - this.height) / 2;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._rankList.dispose();
            this._pageSelecter.dispose();
            this._myRankLink.dispose();
            this._myRank.dispose();
            this._rankList = null;
            this._pageSelecter = null;
            this._myRankLink = null;
            this._myRank = null;
            this.removeListeners();
            return;
        }// end function

        public static function get instance() : WinePartyDonateRankWin
        {
            if (_instance == null)
            {
                _instance = new WinePartyDonateRankWin;
            }
            return _instance;
        }// end function

    }
}
